package com.yutian.selfservice.support.utils;


import org.springframework.lang.Nullable;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;

/**
 * 反射工具类
 *
 * @author zuoqiwen
 * @version 1.0
 * @date 2021-09-01
 */
public class ReflectionUtils extends org.springframework.util.ReflectionUtils {

    public static boolean isAnnotationFromClass(Class clazz, Class annotationClass) {
        Annotation annotation = clazz.getAnnotation(annotationClass);
        return annotation != null;
    }
    public static boolean isAnnotationFromClass(Field filed, Class annotationClass) {
        Annotation annotation = filed.getAnnotation(annotationClass);
        return annotation != null;
    }
    public static void setValue(Field field, @Nullable Object target, @Nullable Object value) {
        try {
            makeAccessible(field);
            field.set(target, value);
        } catch (IllegalAccessException var4) {
            handleReflectionException(var4);
        }

    }
    public static Object getValue(Field field, @Nullable Object target) {
        try {
            makeAccessible(field);
            return field.get(target);
        } catch (IllegalAccessException var3) {
            handleReflectionException(var3);
            throw new IllegalStateException("Should never get here");
        }
    }
}
